package ch.bfh.abcmmh.view.detailview.minipanels;


import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.Observable;
import java.util.Observer;
import javax.swing.JLabel;
import javax.swing.JPanel;
import ch.bfh.abcmmh.view.detailview.streets.StreetPanel;

public class SpeedLimitPanel extends JPanel implements Observer {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	int radius=50;
	JLabel label;
	bigCircle bigC;
	miniCircle miniC;
	int xposition;
	int streetdelay;
	StreetPanel streetPanel;
	
	public SpeedLimitPanel(int speedLimit, int xposition, StreetPanel streetPanel){
		this.streetdelay=0;
		this.xposition=xposition;
		this.streetPanel= streetPanel;
		bigC= new bigCircle();
		miniC = new miniCircle();
		this.label=new JLabel(Integer.toString(speedLimit));
		label.setOpaque(false);
		label.setVisible(true);
		
		
		//label.setBackground(Color.black);
	    Dimension size = new Dimension(50,50);
	    setPreferredSize(size);
	    setMinimumSize(size);
	    setMaximumSize(size);
	    setSize(size);
	    setLayout(null);
	    streetPanel.getStreetController().addObserver(this);
	    miniC.add(label);
	    miniC.repaint();
	    bigC.add(miniC);
	    bigC.repaint();
	    this.add(bigC);
	    this.repaint();
	   
	    this.setLocation(xposition, 0);
	    this.setVisible(true);
	    this.repaint();
	    
	    streetPanel.repaint();
	 

	   
	   
	}

	 class miniCircle extends JPanel{
		 
		 /**
		 * 
		 */
		private static final long serialVersionUID = 1L;
		miniCircle(){
			    Dimension size = new Dimension(40,40);
			    setPreferredSize(size);
			    setMinimumSize(size);
			    setMaximumSize(size);
			    setSize(size);
			    streetPanel.repaint();

	
			 
		 }
		 public void paintComponent(Graphics g) {
		      
		        g.setColor(Color.white);
		        g.fillRoundRect(0,0, getWidth()-1, getHeight()-1, radius, radius);
		
		   }
	}
	 
	 class bigCircle extends JPanel{
		 /**
		 * 
		 */
		private static final long serialVersionUID = 1L;
		public bigCircle(){
			    Dimension size = new Dimension(50,50);
			    setPreferredSize(size);
			    setMinimumSize(size);
			    setMaximumSize(size);
			    setSize(size);
			    streetPanel.repaint();

			    
		 }
		 public void paintComponent(Graphics g) {
		    
		        g.setColor(Color.red);
		        g.fillRoundRect(0,0, getWidth()-1, getHeight()-1, radius, radius);

		   }
	}

	@Override
	public void update(Observable arg0, Object arg1) {
		this.streetdelay=streetPanel.getStreetController().getCurrentPos();
		
		this.setLocation(xposition - streetdelay, 0);
		repaint();
		streetPanel.repaint();
		
		
		
	}

}
